package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SpuManageController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-08-19 10:40
 * @Version 1.0
 */

@Api(tags = "spu操作")
@RestController
@RequestMapping("/admin/product")
public class SpuManageController {

 @Autowired
 private ManageService manageService;

 /**
  * 根据三级id查询商品列表
  *
  * @param size
  * @param page
  * @return
  */
 @GetMapping("/{page}/{size}")
 public Result getsupInfoList(@PathVariable Long page,
                              @PathVariable Long size,
                              SpuInfo spuInfo) {

  Page<SpuInfo> spuInfoPage = new Page<>(page, size);
  IPage<SpuInfo> iPage = manageService.getSpuInfoList(spuInfoPage, spuInfo.getCategory3Id());
  return Result.ok(iPage);
 }

 /**
  * 查询平台所有的销售属性名称
  *
  * @return
  */
 @GetMapping("/baseSaleAttrList")
 public Result getBaseSaleAttrList() {
  List<BaseSaleAttr> baseSaleAttrList = manageService.getBaseSaleAttrList();
  return Result.ok(baseSaleAttrList);
 }

 /**
  * 保存商品信息 spuinfo
  *
  * @param spuInfo
  * @return
  */
 @PostMapping("/saveSpuInfo")
 public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
  // 调用服务层方法
  manageService.saveSpuInfo(spuInfo);
  return Result.ok();
 }

 /**
  * 根据spuid获取图片列表
  *
  * @param spuId
  * @return
  */
 @GetMapping("/spuImageList/{spuId}")
 public Result getSpuImageList(@PathVariable Long spuId) {
  List<SpuImage> spuImageList = manageService.getSpuImageList(spuId);
  return Result.ok(spuImageList);
 }

 /**
  * 根据spuid 获取到销售属性-销售属性值
  *
  * @param spuId
  * @return
  */
 @GetMapping("/spuSaleAttrList/{spuId}")
 public Result spuSaleAttrList(@PathVariable Long spuId) {
  List<SpuSaleAttr> spuSaleAttrList = manageService.getSpuSaleAttrList(spuId);
  return Result.ok(spuSaleAttrList);
 }

}